package com.imagination.applet.controller.api;

import com.imagination.applet.controller.api.request.StarChargeRequest;
import com.imagination.applet.controller.api.response.OrderQueryResponse;
import com.imagination.applet.domain.revenue.charge.service.StarChargeService;
import com.imagination.applet.domain.revenue.identity.service.VirtualIdentityBuildingService;
import com.imagination.applet.domain.support.payment.service.PayService;
import com.imagination.applet.infrastructure.common.RestResponse;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import com.wechat.pay.java.service.payments.model.Transaction;
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/order")
//@Tag(name = "订单服务")
public class OrderController {

    private final StarChargeService service;
    private final VirtualIdentityBuildingService virtualIdentityBuildingService;
    private final PayService payService;

    @PostMapping(value = "/star")
//    @Operation(summary = "创建星星充值订单")
    public RestResponse<PrepayWithRequestPaymentResponse> starOrderPrepay(@RequestBody @Validated StarChargeRequest request) {
        return RestResponse.ok(service.submit(request.getLevel()));
    }

    @GetMapping(value = "/star")
//    @Operation(summary = "查询星星充值订单（未实现）")
    public RestResponse<OrderQueryResponse> starOrderQuery(@RequestParam String transNo) {
        return RestResponse.ok();
    }

    @PostMapping(value = "/virtual-identity")
//    @Operation(summary = "购买虚拟分身")
    public RestResponse<PrepayWithRequestPaymentResponse> virtualIdentityPrepay() {
        return RestResponse.ok(virtualIdentityBuildingService.prepay());
    }

    @GetMapping(value = "/virtual-identity")
//    @Operation(summary = "查询虚拟分身订单（未实现）")
    public RestResponse<OrderQueryResponse> virtualIdentityPrepay(@RequestParam String transNo) {
        return RestResponse.ok();
    }

    @GetMapping(value = "/wechat")
//    @Operation(summary = "查询微信订单")
    public RestResponse<Transaction> wechatOrderQuery(@RequestParam String transNo) {
        Transaction transaction = payService.queryOrderByOutTradeNo(transNo);
        return RestResponse.ok(transaction);
    }
}
